home *** CD-ROM | disk | FTP | other *** search
/ Light ROM Gold / Light ROM Gold.iso / arexx / movscn32.rex < prev    next >
OS/2 REXX Batch file  |  1995-08-11  |  25KB  |  807 lines

  1. /* CMD:  Move Scene v3.2
  2.  * Move Lightwave Scene file and all that it is used in it, to a new
  3.  * place.  Useful for transfering scenes to another computer.
  4.  * It will move all of your images, rearrange your scene file so
  5.  * that the objects will load from the new directory you specified.
  6.  * It will also take into account if you are moving your scenes into
  7.  * 3.5" disks and measure how much space is left, requesting new
  8.  * disks and initialize them in Amiga or IBM format.
  9.  *
  10.  * To run the macro, you will need these Workbench programs in C:
  11.  * copy, makedir, list, delete, format, info and rename.
  12.  *
  13.  * To use PC disks, you should have CrossDos (included in WB 2.1+) and
  14.  * installed for your internal drive (DF0).
  15.  *
  16.  * If using lha, you should have lha - if you prefer another lha
  17.  * compressor, just use your favorite editor to change the LHA_C
  18.  * variable path to the compressor you like.
  19.  * You could probably modify LHA to work with ARJ, or other PC compressor.
  20.  *
  21.  * If using compress, you should also have compress.b16 in C:.
  22.  *
  23.  * NOTE: This version 3.2 is still beta.  The reason I decided to
  24.  *       release it was that many people seemed to need it.
  25.  *       In this version, if you use any type of compression, you
  26.  *       will not be able to load the file into LW later.  You will
  27.  *       have to rename all the files.  This might be fixed later.
  28.  *       Also, this macro assumes all your images are saved as IFF.
  29.  *       If not, change the IFF_EXT variable to what you like.
  30.  *       Video Toaster image files are not supported.
  31.  *       Bugs, comments and suggestions to ggarramuno@sicoar1.satlink.net
  32.  *
  33.  * 8/94 Version 1.0  - By Gonzalo Garramuno (C) 1994
  34.  * 11/94 Version 2.0 - By Gonzalo Garramuno (C) 1994
  35.  *                     > fixed bug with objects bigger than 65,535 bytes.
  36.  *                     > added option to turn off copying image and 
  37.  *                       image sequences.
  38.  *                     > added option for changing the paths of the
  39.  *                       scene and object files to point to the new
  40.  *                       place.
  41.  *                     > added option for multiple disks, formatting
  42.  *                       them as needed.
  43.  *                     > added lha compression if lha is in C:
  44.  *                       note: if using lha, avoid files with bad
  45.  *                             names (ie. those that have wildcards
  46.  *                             characters in them, such as ?,#,),etc)
  47.  *
  48.  * 3/95 Version 3.0 (C) 1995 Gonzalo Garramuno
  49.  *                   > added shortening files to 8 characters.
  50.  *                   > added manual rename of files to 8 chrs. when
  51.  *                     automatic will not work.
  52.  *                   > changing spaces to underscores.
  53.  *                   > added compress compression for SGI compatibility.
  54.  *                     watch out for wrong characters: !, etc.
  55.  *                   > added changing of slashes.
  56.  * 4/95 Version 3.1  > added moving to remote directory.
  57.  * 7/95 Version 3.2  > corrected extensions to LWS, LWO and IFF
  58.  *                     (Can be modified easily, if needed).
  59.  *                   > corrected silly bug when moving an scene NOT to
  60.  *                     a remote directory.
  61.  */
  62.  
  63. /* Extensions Variables */
  64.  
  65. SCENE_EXT = "LWS"
  66. OBJECT_EXT = "LWO"
  67. IFF_EXT = "IFF"
  68.  
  69. /* Compression commands */
  70.  
  71. LHA_C = "LHA"
  72. COMP_C = "compress.b16"
  73.  
  74. call addlib "LWModelerARexx.port", 0
  75. call addlib "rexxsupport.library", 0, -30, 0
  76. signal on error
  77. signal on syntax
  78.  
  79. sysnam = 'Move Scene'
  80. version = 'Move Scene v3.2'
  81. statfil="T:move.scene"
  82. image = 3
  83. path = 1
  84. disk = 1
  85. dnum = 1
  86. comp = 1
  87. short = 0
  88. repl = 0
  89. slash = 0
  90. rem = 0
  91. remname = ""
  92.  
  93. cant = 0
  94. nfil = 0
  95.  
  96. if (exists(statfil)) then do
  97.     if (~open(state, statfil, 'R')) then break
  98.     if (readln(state) ~= version) then break
  99.     l1 = readln(state)
  100.     l2 = readln(state)
  101.     image = readln(state)
  102.     path = readln(state)
  103.     disk = readln(state)
  104.     comp = readln(state)
  105.     short = readln(state)
  106.     repl = readln(state)
  107.     slash = readln(state)
  108.     rem = readln(state)
  109.     remname = readln(state)
  110.     call close state
  111. end
  112.  
  113. if l1="L1" then do
  114. /* If you have Lightwave installed somewhere else other than
  115.    Toaster: then change the path below */
  116.     l1="Toaster:3D/Scenes"
  117.     name1=""
  118.     l2="ram:"
  119.     name2=""
  120. end
  121. else do
  122.     filenam="/"
  123.     s=2
  124.     if lastpos("/",l1)=0 then do
  125.         filenam=":"
  126.         s=1
  127.     end
  128.     name1=right(l1,length(l1)-lastpos(filenam,l1))
  129.     l1=left(l1,pos(name1,l1)-s)
  130.     
  131.     filenam="/"
  132.     s=2
  133.     if lastpos("/",l2)=0 then do
  134.         filenam=":"
  135.         s=1
  136.     end
  137.     if length(l2)=lastpos(filenam,l2) then filenam=""
  138.     name2=right(l2,length(l2)-lastpos(filenam,l2))
  139.     l2=left(l2,pos(name2,l2)-s)
  140. end
  141.  
  142. filenam=getfilename("-- Lightwave Scene --",l1,name1)
  143. if filenam ="(none)" then exit
  144.  
  145. call REQ_BEGIN("Move Scene")
  146.       id_disk=REQ_ADDCONTROL("Copy to?",'CH',"Directory",
  147.                            "Multiple"d2c(160)"DF0: Multiple"d2c(160)"PC0:")
  148.       id_image=REQ_ADDCONTROL("Copy Images?",'CH',"No Images"d2c(160)"only
  149.                               Images"d2c(160)"and"d2c(160)"Sequences")
  150.       id_path=REQ_ADDCONTROL("Change Paths",'B')
  151.  
  152.       id_comp=REQ_ADDCONTROL("Compression",'CH',"None LHA Compress")
  153.       id_short=REQ_ADDCONTROL("Shorten filenames to 8 chrs?",'B')
  154.       id_repl=REQ_ADDCONTROL("Change spaces to underscores?",'B')
  155.       id_slash=REQ_ADDCONTROL("Change / to \?",'B')
  156.       id_remote=REQ_ADDCONTROL("Use a remote directory?",'B')
  157.       id_remname=REQ_ADDCONTROL("Name of Remote Dir (add : or /)",'S')
  158.  
  159.       call REQ_SETVAL(id_disk,disk)
  160.       call REQ_SETVAL(id_image,image)
  161.       call REQ_SETVAL(id_path,path)
  162.       call REQ_SETVAL(id_comp,comp)
  163.       call REQ_SETVAL(id_short,short)
  164.       call REQ_SETVAL(id_repl,repl)
  165.       call REQ_SETVAL(id_slash,slash)
  166.       call REQ_SETVAL(id_remote,rem)
  167.       call REQ_SETVAL(id_remname,remname)
  168.  
  169. ok=REQ_POST()
  170.  
  171. If ok~=1 Then exit
  172.  
  173. disk = REQ_GETVAL(id_disk)
  174. image = REQ_GETVAL(id_image)
  175. path = REQ_GETVAL(id_path)
  176. comp = REQ_GETVAL(id_comp)
  177. short = REQ_GETVAL(id_short)
  178. repl = REQ_GETVAL(id_repl)
  179. slash = REQ_GETVAL(id_slash)
  180. rem = REQ_GETVAL(id_remote)
  181. remname = REQ_GETVAL(id_remname)
  182.  
  183. select
  184.     when disk=1 then do
  185.         Drawer=getfilename("-- Drawer to Create --",l2,name2)
  186.         if Drawer ="(none)" then exit
  187.         Drawer = short(Drawer,"")
  188.     end
  189.     when disk=2 then Drawer="DF0:"
  190.     otherwise Drawer="PC0:"
  191. end
  192.  
  193. remDraw = Drawer || "/"
  194. if rem = 1 then remDraw = remname
  195.  
  196. /* Save preferences just in case */
  197. if (open(state, statfil, 'W')) then do
  198.     call writeln state, version
  199.     call writeln state, filenam
  200.     call writeln state, Drawer
  201.     call writeln state, image
  202.     call writeln state, path
  203.     call writeln state, disk
  204.     call writeln state, comp
  205.     call writeln state, short
  206.     call writeln state, repl
  207.     call writeln state, slash
  208.     call writeln state, rem
  209.     call writeln state, remname
  210.     call close state
  211. end
  212.  
  213. if disk>1 then call askdisk()
  214.  
  215. if comp = 2 then Drawer = Drawer || ".lha"
  216. if comp = 3 then Drawer = Drawer || ".Z"
  217.  
  218. /* Number of Images in Scene and/or Objects */
  219. img=0
  220.  
  221. if (exists(filenam)) then do
  222.  
  223. /* Erase if there was a previous one by mistake */
  224.     address command
  225.     if (disk=1)&(exists(Drawer)) then do
  226.         if notify(2,"Delete "||Drawer"?")=0 then exit
  227.         'delete "'Drawer'" all  >NIL:'
  228.     end
  229.  
  230.     obj=0
  231.     if (~open(state, filenam, 'R')) then exit
  232.     parse value readln(state) with type .
  233.     if type~="LWSC" then do
  234.         Bummer("Not a Lightwave ASCII Scene!")
  235.     end
  236.     else do while eof(state)=0
  237.         type=readln(state)
  238.         if left(type,11)="LoadObject " then do
  239.         obj=obj+1
  240.             object.obj = substr(type,12)
  241.                 newobj.obj = short(object.obj,OBJECT_EXT)
  242.         end
  243.  
  244. /* Handle images in scene file
  245.  * Background, Foreground, Alpha, Displacement and Clip maps */
  246.         if image > 1 then do
  247.             l=pos(" ",type)
  248.             if l=0 then l=1
  249.             if (left(type,l)="BGImage "),
  250.               |(left(type,l)="FGImage "),
  251.               |(left(type,l)="FGAlphaImage "),
  252.               |(left(type,l)="TextureImage ") then do
  253.                 img = img + 1
  254.                    image.img = substr(type,l+1)
  255.                 newimg.img = short(image.img,IFF_EXT)
  256.             end
  257.         end
  258.     end
  259.     call close state
  260.  
  261. /* Make dir and copy scene file to it */
  262.     if disk=1 then call makdir(Drawer)
  263.     newnam = short(filenam,SCENE_EXT)
  264.     call cop(filenam,Drawer,newnam)
  265.  
  266.     if disk=1 then Drawer=Drawer||"/"
  267.  
  268. /* Check repeated objects when shortening to 8 chrs */
  269. if (short = 1) & (obj > 1) then do
  270.     do i = 2 to obj
  271.         do l = (i - 1) to 1 by -1
  272.                 if (short(newobj.i) = short(newobj.l)),
  273.                    & (newobj.i ~= newobj.l) then do
  274.                 call REQ_BEGIN("Please manually shorten "GetName(object.i))
  275.                    id_name=REQ_ADDCONTROL("Type New Name (8 chrs)","S",8)
  276.  
  277.                    ok=REQ_POST()
  278.  
  279.                    if ok = 0 then exit
  280.  
  281.                    type = search(newobj.i)
  282.                    type = left(newobj.i,type)
  283.  
  284.                    newobj.i = short(type || REQ_GETVAL(id_name),OBJECT_EXT)
  285.                    l = l + 1
  286.                 end
  287.         end l
  288.     end i
  289. end
  290.  
  291. /*****************************************/
  292. /* Copy all objects to Objects Directory */
  293. /*****************************************/
  294.  
  295.     if obj>0 then do
  296.         call METER_BEGIN(obj+1,"Moving Objects")
  297.         call makdir(Drawer"Objects")
  298.         do i=1 to obj
  299.             call METER_STEP()
  300.             call cop(object.i,Drawer"Objects",newobj.i)
  301.             if image > 1 then do
  302.                if (~open(state, object.i, 'R')) then exit
  303.                seq=0
  304.  
  305. /* Type is an array, to avoid problems with big objects */
  306.                do while eof(state) = 0
  307.             seq = seq + 1
  308.                 type.seq = readch(state,65535)
  309.                end
  310.                call close state
  311.         do t=1 to seq
  312.                        l=0
  313.                        l2=1
  314.                         do while (l<length(type.t))&(length(type.t)>3)
  315. /* Search for "IMG" in object, which tells us about an image file */
  316.                         l = pos("IMG",type.t,l2)
  317.                         if l ~= 0 then do
  318.                             l2 = pos(d2c(0),type.t,l+4)
  319.                             l2 = l2-l-5
  320.                             check = 0
  321.                            do s = 1 to img
  322.                         if substr(type.t,l+5,l2)=image.s then check = 1
  323.                         if substr(type.t,l+5,l2)="(none)" then check = 1
  324.                     end s
  325.                     if check=0 then do
  326.                                     img = img+1
  327.                                    image.img = substr(type.t,l+5,l2)
  328.                                     newimg.img = short(image.img,IFF_EXT)
  329.                     end
  330.                     l2 = l+l2
  331.                     l = l2
  332.                 end
  333.                 else l = length(type.t)
  334.                     end
  335.         end t
  336.         end
  337.            end i
  338.     end
  339.     call METER_END
  340.  
  341. /* Check repeated images when shortening to 8 chrs */
  342.  
  343. if (short = 1) & (img > 1) then do
  344.     do i = 2 to img
  345.         do l = (i - 1) to 1 by -1
  346.                 if short(newimg.i) = short(newimg.l) then do
  347.                 call REQ_BEGIN("Please manually shorten "GetName(image.i))
  348.                    id_name=REQ_ADDCONTROL("Type New Name (8 chrs)","S",8)
  349.  
  350.                    ok=REQ_POST()
  351.  
  352.                    if ok = 0 then exit
  353.  
  354.                    type = search(newimg.i)
  355.                    type = left(newimg.i,type)
  356.  
  357.                    newimg.i = short(type || REQ_GETVAL(id_name),IFF_EXT)
  358.                    l = l + 1
  359.                 end
  360.         end l
  361.     end i
  362. end
  363.  
  364. /*******************************************************/
  365. /* Copy all images (and sequences) to Images directory */
  366. /*******************************************************/
  367.  
  368.     if img>0 then do
  369.         call makdir(Drawer"Images")
  370.         call METER_BEGIN(img+1,"Moving Images")
  371.         call METER_STEP
  372.         do i = 1 to img
  373.             call METER_STEP
  374. /* Handle sequences: create special dir */
  375.             if (right(image.i,11) = " (sequence)") then do
  376.           if image = 3 then do
  377.                     name1 = short(CheckSeq(image.i),IFF_EXT)
  378.                     name1 = left(name1,length(name1)-1)
  379.                     image.i = left(image.i,length(image.i)-11)
  380.                 call makdir(Drawer"Images/"||name1)
  381.             call cop(image.i"#?",Drawer"Images/"name1,newimg.i)
  382.           end
  383.             end
  384. /* Handle image files */
  385.             else do
  386.                 call cop(image.i,Drawer"Images",newimg.i)
  387.             end
  388.          end i
  389.         call METER_END
  390.     end
  391.  
  392.  
  393.     if path = 1 then do
  394.  
  395.         name1=""
  396.  
  397. /***************************/
  398. /* Modify Scene file paths */
  399. /***************************/
  400.  
  401.         if disk>1 then do
  402.             Drawer = "Disk"
  403.             call checkdisk2(files.1)
  404.             name1="1:"
  405.         end
  406.  
  407.         l=search(filenam)
  408.         file=Drawer||name1||right(filenam,length(filenam)-l)
  409.         file=short(file,SCENE_EXT)
  410.         if (~open(state, filenam, 'R')) then break
  411.         if (~open(state2, file, 'W')) then break
  412.  
  413.         do while eof(state)=0
  414.             type = readln(state)
  415.  
  416.             if left(type,11)="LoadObject " then do
  417.                 file = delstr(type,1,11)
  418.                 l = search(file)
  419.                 i = checkdisk(file)
  420.                 type = "LoadObject " || remDraw || i || "Objects/"
  421.                     name = short(right(file,length(file)-l),OBJECT_EXT)
  422.                 type = type || name
  423.             end
  424.             if image > 1 then do
  425.                 l = pos(" ",type)
  426.                 if (left(type,l)="BGImage "),
  427.                   |(left(type,l)="FGImage "),
  428.                   |(left(type,l)="FGAlphaImage "),
  429.                   |(left(type,l)="TextureImage ") then do
  430.                         file = delstr(type,1,l)
  431.                         if file~="(none)",
  432.                        |((right(file,11)=" (sequence)")&(image=3)) then do
  433.                           t=search(file)
  434.                           dnum = checkdisk(file)
  435.                           test = 8
  436.                           name1 = short(CheckSeq(file))
  437.                           if name1 ~= "" then test = 5
  438.                           name = right(file,length(file)-t)
  439.                           name = short(name,"",test)
  440.                           file = remDraw || dnum || "Images/" || name1,
  441.                                || name
  442.                           type = left(type,l) || file
  443.                     end
  444.         end
  445.             end
  446.         if slash = 1 then type = translate(type,"\","/")
  447.         call writeln state2, type
  448.         end
  449.  
  450.         call close state
  451.         call close state2
  452.  
  453. /***************************************/
  454. /* Now modify the objects' images path */
  455. /***************************************/
  456.  
  457.         call METER_BEGIN(obj+1,"Modifying paths")
  458.         do i=1 to obj
  459.               call METER_STEP()
  460.             l = search(object.i)
  461.             t = checkdisk2(object.i)
  462.             file = Drawer || t || "Objects/"
  463.             name = short(right(object.i,length(object.i)-l),OBJECT_EXT)
  464.             file = file || name
  465.  
  466.             if (~open(state, object.i, 'R')) then break
  467.             if (~open(state2, file, 'W')) then break
  468.  
  469.         do while eof(state)=0
  470.                type = readch(state,10000)
  471.                l=0
  472.                l2=1
  473.                do while (l<length(type))&(length(type)>3)
  474.                l = pos("IMG",type,l2)
  475.                 if l ~= 0 then do
  476.                     l2 = pos(d2c(0),type,l+4)
  477.                   l2 = l2-l-5
  478. /*                 img = img+1 */
  479.                 file = substr(type,l+5,l2)
  480.                     if file~="(none)",
  481.                     |((right(file,11)=" (sequence)")&(image=3)) then do
  482.                         t=search(file)
  483.                         dnum = checkdisk(file)
  484.                         test = 8
  485.                         name1 = short(CheckSeq(file))
  486.                         if name1 ~= "" then test = 5
  487.                         name = right(file,length(file)-t)
  488.                         name = short(name,"",test)
  489.                         file = remDraw || dnum || "Images/" || name1,
  490.                                || name
  491.                         file = left(type,l+3)|| d2c(length(file)+2) || file
  492.                         type = substr(type,l+l2+5)
  493.                     end
  494.                     else file = ""
  495.                   type = file || type
  496.             l2 = l+l2
  497.             l = l2
  498.                end
  499.                else l = length(type)
  500.                end
  501.         if slash = 1 then type = translate(type,"\","/")      
  502.         call writech state2, type
  503.         end
  504.         call close state
  505.         call close state2
  506.         end i
  507.         call METER_END()
  508.     end
  509.     file = SHOWLIST("V",,"|")
  510. end
  511. else do
  512.     Bummer("Can't open Scene file : "filenam)
  513. end
  514. exit
  515.  
  516. /* Ask to insert new disk */
  517.  
  518. askdisk: PROCEDURE EXPOSE dnum Drawer size obj img
  519.  
  520. t=notify(3,"@Please insert a new disk in DF0:",,
  521.            "!The disk will be formatted. All Information will be lost",,
  522.            "Are you sure you want to continue?")
  523. if t=0 then exit
  524.  
  525. call METER_BEGIN(2,"Formatting disk")
  526. call METER_STEP
  527.  
  528. address command
  529. "format DRIVE" '"'Drawer'"' "NAME Disk"dnum "NOICONS >NIL:"
  530. call METER_END()
  531.  
  532. if img>0 then call makdir(Drawer||"Images")
  533. else do
  534.     if obj>0 then call makdir(Drawer||"Objects")
  535. end
  536.  
  537. /* Get info on size of all disks */
  538. "info >RAM:info.testfile "Drawer
  539.  
  540. /* Find the size of the disk we are working with */
  541. if (~open(test, "RAM:info.testfile", 'R')) then break
  542.  
  543. do i=1 to 3
  544.     text = readln(test)
  545. end i
  546.  
  547. text = readln(test)
  548. text = word(text,2)
  549. size = left(text,length(text)-1)*1000
  550.  
  551. call close test
  552.  
  553. "delete ram:info.testfile > NIL:"
  554.  
  555. return
  556.  
  557.  
  558. /* Makedir procedure */
  559.  
  560. makdir: PROCEDURE
  561.     parse arg source
  562.  
  563.     address command
  564.     if ~exists(source) then do
  565.         "makedir" '"'source'"'
  566.     end
  567. return
  568.  
  569. /* Insert disk message */
  570.  
  571. insdisk: PROCEDURE EXPOSE Drawer
  572.     parse arg num
  573.  
  574. loop:
  575.     call notify(1,"Please insert Disk" num "in any drive")
  576. /* Check that the user put the right disk in before going on */
  577.     Drives = SHOWLIST("V",,"|")
  578.     l = pos(UPPER(Drawer || num || "|"),Drives)
  579.     if l = 0 then call loop
  580. return
  581.  
  582. /* Copy procedure. Checks for disk size */
  583. Cop:
  584. /* PROCEDURE EXPOSE disk Drawer cant size dnum obj img,
  585.                       nfil files. fdisk. lha image */
  586.     parse arg source, dest, altsrc
  587.  
  588.     if comp = 2 then do
  589.             source = lharc(source)
  590.     end
  591.  
  592.     if comp = 3 then do
  593.             source = compress(source)
  594.     end
  595.  
  596.     altsrc = GetName(altsrc)
  597.  
  598.     if disk > 1 then do
  599.         add = 0
  600.         if (right(source,2) = "#?") then do
  601. /* Get file size for all the images in sequence
  602.  * All the images of a sequence should fit in the same device.
  603.  */
  604.             "list" source ">ram:info.testfile files quick lformat=%l"
  605.             if (~open(test, "RAM:info.testfile", 'R')) then break
  606.             do while eof(test)=0
  607.                 text = readln(test)
  608.                 if text~="" then add = add + text
  609.             end
  610.             call close test
  611.             "delete ram:info.testfile > NIL:"
  612.         end
  613.         else do
  614.             t = statef(source)
  615.             add = word(t,2)
  616.         end
  617.         if add > size then do
  618.           call notify(1,"You will not be able to fit the",,
  619.                         "current scene on floppys.  Use the Directory",,
  620.                         "Option with a backup program or try compressing",,
  621.                         "your objects before running the macro.")
  622.             exit
  623.         end
  624.         if (cant + add) > size then do
  625.                  dnum = dnum + 1
  626.                  cant = 0
  627.                  call askdisk()
  628.         end
  629.         cant = cant + add
  630.  
  631. /* Add another file to list */
  632.         nfil = nfil + 1
  633.         files.nfil = source
  634.         fdisk.nfil = dnum
  635.     end
  636.  
  637.     if right(source,2)="#?" then do
  638.         "list" source ">ram:info.testfile files quick lformat=%n"
  639.          t = statef("ram:info.testfile")
  640.          add = word(t,2)
  641.          if add = 0 then do
  642.           type = left(GetName(source),length(GetName(source))-2)
  643.           call notify(1,"The sequence "type" used in the",,
  644.                       "scene is no longer in the same place",,
  645.                       "or it has been deleted.  Go into Layout",,
  646.                       "and manually change the scene.")
  647.       "delete ram:info.testfile > NIL:"
  648.           exit
  649.          end
  650.     end
  651.     else if ~exists(source) then do
  652.         call notify(1,"The file "GetName(source)" used in the",,
  653.                       "scene is no longer in the same place",,
  654.                       "or it has been deleted.  Go into Layout",,
  655.                       "and manually change the scene.",,
  656.                       "If it is an image, save all objects too.")
  657.         exit
  658.     end
  659.     
  660.     address command
  661.     if right(source,2)="#?" then do
  662.             if (~open(test, "RAM:info.testfile", 'R')) then break
  663.             do while eof(test)=0
  664.                 text = readln(test)
  665.  
  666.                 l = search(source)
  667.                 if text ~= "" then do
  668.                   t = pos("0",text)
  669.                   altsrc = short(text,"",5)
  670.           if short = 1 then altsrc = altsrc || substr(text,t,3)
  671.                   "copy" '"'left(source,l) || text'" "'dest'/'altsrc'"'
  672.                 end
  673.             end
  674.             call close test
  675.         "delete ram:info.testfile > NIL:"
  676.     end
  677.     else do
  678.     "copy" '"'source'" "'dest'/'altsrc'" > NIL:'
  679.     end
  680.  
  681. /* Erase ram: .lha and .Z files */
  682.     if comp > 1 then 'delete "'source'" all >NIL:'
  683. return
  684.  
  685. /* Find disk number for a file */
  686.  
  687. Checkdisk: PROCEDURE EXPOSE disk nfil files. fdisk. image
  688.     parse arg filenam
  689.  
  690.     if disk = 1 then return ""
  691.     if (right(filenam,11) = " (sequence)")&(image=3) then do
  692.         filenam = left(filenam,length(filenam)-11)||"#?"
  693.     end
  694.     do i=1 to nfil
  695.         if filenam = files.i then return fdisk.i || ":"
  696.     end i
  697.     return
  698.  
  699. /* Check disk in drive to see if it is the one where file is.
  700.  * If not, ask for disk */
  701.  
  702. Checkdisk2: PROCEDURE EXPOSE disk nfil files. fdisk. Drawer
  703.     parse arg filenam
  704.  
  705.     t = checkdisk(filenam)
  706.     if t = "" then return ""
  707.  
  708.     t=left(t,1)
  709.     Drives = SHOWLIST("V",,"|")
  710.     l = pos(UPPER(Drawer || t || "|"),Drives)
  711.     if l = 0 then call insdisk(t)
  712.     t = t || ":"
  713.     
  714. return t
  715.  
  716. CheckSeq: PROCEDURE EXPOSE image
  717.     parse arg filenam
  718.  
  719.         test = ""
  720.         if (right(filenam,11) = " (sequence)")&(image=3) then do
  721.             filenam = left(filenam,length(filenam)-11)
  722.             l = length(filenam) - search(filenam)
  723.             test = right(filenam,l) || "/"
  724.         end
  725. return test
  726.  
  727. Search: PROCEDURE
  728.     parse arg filenam
  729.         i = lastpos("/",filenam)
  730.         l = lastpos(":",filenam)
  731.         if l>i then i=l
  732. return i
  733.  
  734. /* Strip extensions and get name of file only */
  735. GetName: PROCEDURE
  736. parse arg name
  737.     l = search(name)
  738.     if n ~= 0 then do
  739.         name=right(name,length(name)-l)
  740.     end
  741. return name
  742.  
  743. /* Compress files to ram: before copying them */
  744.  
  745. Lharc: PROCEDURE EXPOSE LHA_C
  746.     parse arg source
  747.  
  748.     l = search(source)
  749.     file = "ram:" || right(source,length(source)-l)
  750.  
  751.     LHA_C ' -x a "'file||'.lha"' '"'source'" >NIL:'
  752.     'rename "'file||'.lha"' '"'file'"'
  753.  
  754. return file
  755.  
  756. compress: PROCEDURE EXPOSE short repl COMP_C
  757.     parse arg source
  758.  
  759.     l = search(source)
  760.     l2 = short
  761.     short = 1
  762.     file = short("ram:" || right(source,length(source)-l),"")
  763.     short = l2
  764.     
  765.     'copy "'source'" "'file'"'
  766.     COMP_C' "'file'"'
  767.     file = file || ".Z"
  768.  
  769. return file
  770.  
  771. Short: PROCEDURE EXPOSE short repl
  772.     parse arg file, ext, l2
  773.  
  774.     if right(file,2) = "#?" then file = left(file,length(file)-2)
  775.  
  776.     seq = ""
  777.  
  778.     if right(file,11)=" (sequence)" then do
  779.                  file = left(file,length(file)-11)
  780.                  seq =" (sequence)"
  781.     end
  782.  
  783.     l = search(file)
  784.  
  785.     if (l2 = " ") then l2 = 8
  786.     if (l + l2) > length(file) then l2 = length(file) - l
  787.  
  788.     if repl = 1 then file = translate(file,"_-"," .")
  789.  
  790.     if ext ~= "" then ext = "." || ext
  791.  
  792.     if short = 1 then file = left(file,l) || substr(file,l+1,l2) || ext
  793.  
  794.     file = file || seq
  795.  
  796. return file
  797.  
  798. Bummer:
  799.   parse arg etxt
  800.   t=Notify(1,'!Rexx Script Error','@'ETxt)
  801.   exit
  802.  
  803. syntax:
  804. error:
  805.   call end_all
  806.   t=Notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL)
  807.   exit